<?php
namespace app\modules\common\actions;

use app\lib\ActionBase;
use app\service\data as data;
use app\lib\Code;

class Sms extends ActionBase {
    
    private $_data_sms;
    
    //用户id
    public $phone;
    
    public function __construct() {
        $this->_data_sms = new data\Sms();
    }
    
    public function rules() {
        return [
            //用户注册
            ['phone','required','on'=>'register', 'message'=>'手机号码不能为空'],
        ];
    }
   
    //获取验证码
    public function GetCode($arrInput) {
        $this->setScenario("register");
        $this->load($arrInput, '');
        if (!$this->validate()) {
            formatJson(Code::PARAM, $this->parseErrors2str($this->firstErrors));
        }
        
        $phone = $arrInput['phone'];
        if(strlen($phone) != 11) {
            formatJson(Code::PARAM, '手机号码格式不正确');
        }
        return $this->_data_sms->Register($arrInput);
    }
}